from selenium import webdriver
# from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from time import sleep
from postion import options
from postion import service


class Login():
    def __init__(self, driver):
        self.driver = driver

    def login(self,username,password):
        self.driver.find_element(By.ID, 'ls_username').clear()
        self.driver.find_element(By.ID, 'ls_username').send_keys(username)
        self.driver.find_element(By.ID, 'ls_password').clear()
        self.driver.find_element(By.ID, 'ls_password').send_keys(password)
        sleep(3)
        self.driver.find_element(By.XPATH, '//*[@id="lsform"]/div/div/table/tbody/tr[2]/td[3]/button/em').click()
        sleep(3)

    def logout(self):
        self.driver.find_element(By.LINK_TEXT, '退出').click()
        sleep(3)


if __name__ == '__main__':
    url = r'http://192.168.92.131/upload/'
    username = 'admin'
    password = '123456'
    driver = webdriver.Chrome(options=options,service=service)
    driver.get(url)

    login = Login(driver)
    login.login(username,password)
    login.logout()

    driver.quit()
